﻿using System.Collections.Generic;
using System.Windows.Media;
using FFmpegVideoClip.Lib.AdvancedFragmentProcessor;
using ICSharpCode.AvalonEdit.Highlighting;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    public class ConfigHighlightingDefinition : IHighlightingDefinition
    {
        public static readonly HighlightingBrush DefaultBrush= new SimpleHighlightingBrush(Color.FromRgb(255, 245, 0));
        public static readonly HighlightingBrush RedBrush = new SimpleHighlightingBrush((Color)ColorConverter.ConvertFromString("Red"));
        public static readonly HighlightingRule DefaultBrushRule = new HighlightingRule
        {
            Regex = AdvancedParametersSchemeModule.CommandVariableRegex,
            Color = new HighlightingColor { Name = "Parameter", Foreground = DefaultBrush }
        };
        public static readonly HighlightingRule RedBrushRule = new HighlightingRule
        {
            Regex = AdvancedParametersSchemeModule.CommandVariableRegex,
            Color = new HighlightingColor { Name = "Parameter", Foreground = RedBrush }
        };
        public static readonly ConfigHighlightingDefinition DefaultDefinition = new ConfigHighlightingDefinition();
        public static readonly ConfigHighlightingDefinition RedDefinition = new ConfigHighlightingDefinition(RedBrushRule, RedBrush);
        private HighlightingColor[] highlightingColors;
        private HighlightingRuleSet ruleSet;

        public ConfigHighlightingDefinition(HighlightingRule rule, HighlightingBrush Brush)
        {
            highlightingColors = new HighlightingColor[]
            {
                new HighlightingColor{ Name="Parameter", Foreground= Brush }
            };

            ruleSet = new HighlightingRuleSet();
            ruleSet.Rules.Add(rule);
        }

        public ConfigHighlightingDefinition()
        {
            highlightingColors = new HighlightingColor[]
            {
                new HighlightingColor{ Name="Parameter", Foreground= DefaultBrush }
            };

            ruleSet = new HighlightingRuleSet();
            ruleSet.Rules.Add(DefaultBrushRule);
        }

        public string Name => "Config";

        public HighlightingRuleSet MainRuleSet => ruleSet;

        public IEnumerable<HighlightingColor> NamedHighlightingColors => highlightingColors;

        public IDictionary<string, string>? Properties => null;

        public HighlightingColor GetNamedColor(string name)
        {
            return highlightingColors[0];
        }

        public HighlightingRuleSet GetNamedRuleSet(string name)
        {
            return ruleSet;
        }
    }
}
